package hebClustering.weights;

import hebClustering.documentTypes.Document;
import hebClustering.nlp.Corpus;
import hebClustering.nlp.Token;


/**
 * Implementation of the weight function tf-idf.
 * 
 *	@see <a href="http://en.wikipedia.org/wiki/Tf%E2%80%93idf" target="_blank">tf-idf</a>
 */
public class Tf_IdfWeight implements IWeightFunc {
	

	@Override
	public double calc(Token token,Document doc) {
		double tf,idf;
		
		tf = ( (double) doc.getNumOfRepetitions(token.getText()) )/doc.getTotalNumOfTokens();
		idf = Math.log( ( (double) Corpus.getCorpus().getNumDocs() )/(token.getNumAppearencesInCorpus() ) );
		
		return tf*idf;
	}

}